package cn.iocoder.yudao.module.erp.dal.mysql.stock.goodswarehouselink;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.stock.goodswarehouselink.vo.GoodsWarehouseLinkPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.goodswarehouselink.GoodsWarehouseLinkDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;


/**
 * 物品和仓库的连接 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface GoodsWarehouseLinkMapper extends BaseMapperX<GoodsWarehouseLinkDO> {

    default PageResult<GoodsWarehouseLinkDO> selectPage(GoodsWarehouseLinkPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<GoodsWarehouseLinkDO>()
                .eqIfPresent(GoodsWarehouseLinkDO::getWarehouseId, reqVO.getWarehouseId())
                .eqIfPresent(GoodsWarehouseLinkDO::getGoodsId, reqVO.getGoodsId())
                .betweenIfPresent(GoodsWarehouseLinkDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(GoodsWarehouseLinkDO::getId));
    }
    /*
     * @param goodsId:
      * @return List<GoodsWarehouseLinkDO>
     * @author Max-u-19
     * @description 根据物品id查询连接表中所有的仓库和库存信息
     * @date 2024/1/14 12:45
     */
    default List<GoodsWarehouseLinkDO> selectListByGoodsId(Long goodsId){
//        return selectList(new LambdaQueryWrapperX<GoodsWarehouseLinkDO>()
//                .eq(GoodsWarehouseLinkDO::getGoodsId,goodsId));
        return selectList(GoodsWarehouseLinkDO::getGoodsId, goodsId);
    }

    default List<GoodsWarehouseLinkDO> selectListByGoodsIdsWarehouseId(List<Long> goodsIds, Long warehouseId) {
        return selectList(new LambdaQueryWrapperX<GoodsWarehouseLinkDO>()
                .in(GoodsWarehouseLinkDO::getGoodsId, goodsIds)
                .eq(GoodsWarehouseLinkDO::getWarehouseId, warehouseId));
    }

    default GoodsWarehouseLinkDO selectOneByGoodsIdWarehouseId(Long goodsId, Long warehouseId) {
        return selectOne(new LambdaQueryWrapperX<GoodsWarehouseLinkDO>()
                .eq(GoodsWarehouseLinkDO::getGoodsId, goodsId)
                .eq(GoodsWarehouseLinkDO::getWarehouseId, warehouseId));
    }

    default List<GoodsWarehouseLinkDO> selectListByWarehouseIdGoodsIds(Long warehouseId, List<Long> goodsIds) {
        return selectList(new LambdaQueryWrapperX<GoodsWarehouseLinkDO>()
                .eq(GoodsWarehouseLinkDO::getWarehouseId, warehouseId)
                .in(GoodsWarehouseLinkDO::getGoodsId, goodsIds));
    }
    /**
     * @author Max-u-19
     * @Description 根据set<goodsId,warehouseId>批量查询库存
     * @date 22:39 2024/4/11
     **/
//    default List<GoodsWarehouseLinkDO> selectListByGoodsIdsWarehouseIds(Set<Pair<Long, Long>> warehouseIdsGoodsIds) {
//        return selectList(new LambdaQueryWrapperX<GoodsWarehouseLinkDO>()
//                .in((GoodsWarehouseLinkDO item) -> new Pair<>(item.getGoodsId(), item.getWarehouseId()), warehouseIdsGoodsIds));
//    }

}